<template>
	<view>
		<ren-dropdown-filter :filterData='filterData' :border="false" :defaultIndex='defaultIndex' @onSelected='change'
			class="u-skeleton-rect">
		</ren-dropdown-filter>
		<view class="margin-lr-sm margin-top-16" v-if="dataList.length">
			<view class="flex justify-between radius bg padding-sm margin-top-16" @click="goOrder(item)"
				v-for="(item,index) in dataList" :key='index'>
				<image :src="item.homepageImg?item.homepageImg: '../../../static/logo.png'"
					style="width: 200rpx;height: 200rpx;border-radius: 10rpx;" mode="aspectFill"></image>
				<view class="flex-sub margin-left text-white flex flex-direction justify-between">
					<view class="flex align-center">
						<image src="../../../static/images/qi.png" style="width: 80rpx;height: 40rpx;"></image>
						<view class="margin-right-xs u-line-1"
							style="display: inline-block;margin-left: 10rpx;width: 340rpx;">
							{{item.myLevel}}
						</view>
					</view>
					<view class="flex  radius" style="line-height: 34upx;">
						<view class="margin-right-xs" style="background: #FBEBF0;color: #FF2D01;padding: 10upx 16upx;">
							距离{{item.distance}}km
						</view>
						<view class="margin-right-xs" style="background: #FBEBF0;color: #FF2D01;padding: 10upx 16upx;">
							{{item.gameName[0]}}
						</view>
					</view>
					<view style="color:#FF1200;font-size: 24rpx;font-family: PingFang-SC-Bold;letter-spacing: 2rpx;">
						<text
							style="font-size: 38rpx;font-weight: bold;">{{isVip? item.memberMoney :item.money}}</text>元/<text>{{item.unit}}</text>
					</view>
					<view style="width: 100%;display: flex;justify-content: space-between;align-items: center;">
						<view class="flex align-center" @click.stop="shop(item.userId)">
							<view class="margin-right-xs">{{item.shopName}}</view>
							<image src="../../../static/images/index/right.png" style="width: 14upx;height: 23upx;">
							</image>
						</view>
						<view style="color: #999999;font-size: 26upx;" v-if="item.count">
							已售{{item.count}}
						</view>
					</view>
				</view>
			</view>
		</view>

		<empty v-if="!dataList.length"></empty>
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				page: 1,
				limit: 10,
				dataList: [],
				isVip: false,
				myId: '',
				city: '',
				defaultIndex: [0, 0, 0],
				filterData: [
					[
						{
							label: '距离优先',
							value: 3,
						},
						{
							label: '人气优先',
							value: 2,
						},{
							label: '同城',
							value: 1,
						}
					],
					[{
							label: '销量',
							value: '',
						},
						{
							label: '从高到低',
							value: 'desc',
						},
						{
							label: '从低到高',
							value: 'asc',
						}
					],
					[{
							label: '价格',
							value: '',
						},
						{
							label: '从高到低',
							value: 'desc',
						},
						{
							label: '从低到高',
							value: 'asc',
						}
					],
				],
				value1: '3',
				value2: '',
				value3: '',
			}
		},
		onLoad() {
			this.isVip = uni.getStorageSync('isVIP') ? uni.getStorageSync('isVIP') : false
			this.myId = uni.getStorageSync('userId')
			this.city = uni.getStorageSync('city')
			this.getDataList()
		},
		methods: {
			// 跳转店铺
			shop(userId) {
				uni.navigateTo({
					url: '/pages/index/game/shop?shopUserId=' + userId
				})
			},
			// 筛选
			change(e) {

				this.value1 = e[0][0].value
				this.value2 = e[1][0].value
				this.value3 = e[2][0].value
				this.getDataList()
				// this.mescroll.resetUpScroll()
			},
			getDataList() {
				this.$Request.get("/app/orderTaking/queryLowTaking", {
					page: this.page,
					limit: this.limit,
					latitude: uni.getStorageSync('latitude'),
					longitude: uni.getStorageSync('longitude'),
					city: uni.getStorageSync('city'),
					condition: this.value1, //智能优选
					salesNum: this.value2, //不限男女
					by: this.value3, //价格
					userId: uni.getStorageSync('userId') ? uni.getStorageSync('userId') : '',
				}).then(res => {
					if (res.code == 0) {
						if (this.page == 1) {
							for (let i = 0; i < res.data.list.length; i++) {
								if (res.data.list[i].distance) {
									res.data.list[i].distance = (res.data.list[i].distance / 1000).toFixed(1)
								}
								if (res.data.list[i].gameName) {
									res.data.list[i].gameName = res.data.list[i].gameName.split(",");
								}
							}
							this.dataList = res.data.list
						} else {
							for (let i = 0; i < res.data.list.length; i++) {
								if (res.data.list[i].distance) {
									res.data.list[i].distance = (res.data.list[i].distance / 1000).toFixed(1)
								}
								if (res.data.list[i].gameName) {
									res.data.list[i].gameName = res.data.list[i].gameName.split(",");
								}
							}
							this.dataList = [...this.dataList, ...res.data.list]
						}
					}
					uni.stopPullDownRefresh();
				});
			},

			// 跳转订单
			goOrder(e) {
				let token = uni.getStorageSync('token')
				if (token) {
					uni.navigateTo({
						url: '/pages/index/game/order?id=' + e.id
					});
				} else {
					uni.navigateTo({
						url: '/pages/public/login'
					});
				}
			},
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getDataList();
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getDataList();
		},
	}
</script>

<style>
	page {
		background-color: #f7f7f7;
	}

	.bg {
		background: #ffffff;
	}
</style>